<template>
  <div v-if="props.readonly && props.readonly==1">{{format}}</div>
  <el-select v-model="name" placeholder="请选择" v-else clearable>
    <el-option v-for="item in options" :key="item.value" :label="item.userName" :value="item._id" />
  </el-select>
</template>

<script setup lang="ts">
const { proxy } = getCurrentInstance();
let props = defineProps(["modelValue", "multiple", "readonly"]);
const emit = defineEmits(["update:modelValue"]);

let options = ref([]);

onMounted(() => {
  getInfo();
});

let format = computed(() => {
  if (!options.value.length) return;
  let index = proxy.$utils.findIndexByField(
    options.value,
    "_id",
    props.modelValue
  );
  if (index != -1) return options.value[index].userName;
});

const name = computed({
  get() {
    return props.modelValue;
  },
  set(value) {
    emit("update:modelValue", value);
  },
});

async function getInfo() {
  options.value = await proxy.$apis.account({
    type: "query",
  });
}
</script>



<style lang="scss" scoped>
.container {
}
</style>